﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Keiho.ServiceModel;

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebGet(UriTemplate = "FileNames", ResponseFormat = WebMessageFormat.Json)]
    ServiceResponse<string[]> GetFileNames();

    [OperationContract]
    [WebGet(UriTemplate = "FileEntries", ResponseFormat = WebMessageFormat.Json)]
    ServiceResponse<FileEntry[]> GetFileEntries();

    [OperationContract]
    [WebGet(UriTemplate = "Files/{fileName}", ResponseFormat = WebMessageFormat.Json)]
    ServiceResponse<byte[]> ReadFile(string fileName);

    [OperationContract]
    [WebGet(UriTemplate = "FilesForHtml/{fileName}", ResponseFormat = WebMessageFormat.Json)]
    void ReadFileForHtml(string fileName);

    [OperationContract]
    [WebInvoke(Method = "PUT", UriTemplate = "Files/{fileName}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    ServiceResponse CreateFile(string fileName, byte[] content);

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    void CreateFileForHtml();

    [OperationContract]
    [WebInvoke(Method = "DELETE", UriTemplate = "Files/{fileName}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    ServiceResponse DeleteFile(string fileName);

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "DeleteFile/{fileName}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    ServiceResponse DeleteFile2(string fileName);
}

[DataContract]
[DebuggerDisplay(@"\{{FileName}\}")]
public class FileEntry
{
    [DataMember]
    public string FileName { get; set; }

    [DataMember(EmitDefaultValue = false)]
    public string ContentLength { get; set; }

    [DataMember(EmitDefaultValue = false)]
    public string LastModified { get; set; }
}
